{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.4"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "source": [
    "# 通用操作"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "source": [
    "## `+` 和 `*`\n",
    "\n",
    "- `+` 可以将两个列表拼接为一个列表\n",
    "- `*` 可以将列表重复指定的次数"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "my_list_1 = [1,2,3] + [4,5,6]\n",
    "my_list_2 = [1,2,3] * 3\n",
    "print(f'my_list_1 = {my_list_1}')\n",
    "print(f'my_list_2 = {my_list_2}')"
   ]
  },
  {
   "source": [
    "## `in` 和 `not in`\n",
    "\n",
    "- `in` 用来检查指定元素是否存在于列表中\n",
    "    - 如果存在，返回 `True`，否则返回 `False`\n",
    "- `not in` 用来检查指定元素是否不在列表中\n",
    "    - 如果存在，返回 `False`，否则返回 `True`"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "students = ['Issac','Qihan Wu','Yupeng Du','Mariah','Acker']\n",
    "result_1 = 'Issac' in students\n",
    "result_2 = 'Steve' in students\n",
    "result_3 = 'Issac' not in students\n",
    "result_4 = 'Steve' not in students\n",
    "print(result_1)\n",
    "print(result_2)\n",
    "print(result_3)\n",
    "print(result_4)"
   ]
  },
  {
   "source": [
    "## `len()`\n",
    "\n",
    "- 获取列表中元素的个数"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "students = ['Issac','Qihan Wu','Yupeng Du','Mariah','Acker']\n",
    "number_of_students = len(students)\n",
    "print(f'number_of_students = {number_of_students}')"
   ]
  },
  {
   "source": [
    "## `min()` 和 `max()`\n",
    "\n",
    "- `min()` 获取列表中的最小值\n",
    "- `max()` 获取列表中的最大值"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "array = [10,20,30,40,50]\n",
    "print(f'min(array) = {min(array)}')\n",
    "print(f'max(array) = {max(array)}')"
   ]
  },
  {
   "source": [
    "# `.index()` 和 `.count()`\n",
    "\n",
    "- 方法和函数基本上是一样的，只不过方法必须通过 `对象.方法()` 的形式调用\n",
    "- 方法实际上就是和对象关系紧密的函数\n",
    "- `.index(x[, i[, j])`\n",
    "    - 获取指定元素在列表中第一次出现时的索引\n",
    "    - `i` 表示查找的起始位置（包含）\n",
    "    - `j` 表示查找的终止位置（不包含）\n",
    "    - 如果获取列表中没有的元素，会抛出异常 `ValueError`\n",
    "- `.count()`\n",
    "    - 统计元素在列表中出现的次数 "
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "students = ['Issac','Qihan Wu','Yupeng Du','Mariah','Acker']\n",
    "index = students.index('Yupeng Du')\n",
    "print(f'index = {index}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "students = ['Issac','Qihan Wu','Yupeng Du','Mariah','Acker']\n",
    "students.index('Steve')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "students = ['Issac','Qihan Wu','Issac','Mariah','Issac']\n",
    "index = students.index('Issac',1)\n",
    "print(f'index = {index}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "students = ['Issac','Qihan Wu','Issac','Mariah','Issac']\n",
    "index = students.index('Issac',1,3) # 不包含 3\n",
    "print(f'index = {index}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "students = ['Issac','Qihan Wu','Issac','Mariah','Issac']\n",
    "count = students.count('Issac')\n",
    "print(f'count = {count}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "students = ['Issac','Qihan Wu','Issac','Mariah','Issac']\n",
    "count = students.count('Steve')\n",
    "print(f'count = {count}')"
   ]
  }
 ]
}